//: #### Other pages
//:
//: * [Demo for `colors` parser](Colors-Demo)
//: * [Demo for `coredata` parser](CoreData-Demo)
//: * [Demo for `files` parser](Files-Demo)
//: * [Demo for `fonts` parser](Fonts-Demo)
//: * [Demo for `ib` parser](InterfaceBuilder-Demo)
//: * [Demo for `json` parser](JSON-Demo)
//: * [Demo for `plist` parser](Plist-Demo)
//: * [Demo for `strings` parser](Strings-Demo)
//: * Demo for `xcassets` parser
//: * [Demo for `yaml` parser](YAML-Demo)

// setup code to make this work in playground
// swiftlint:disable convenience_type
private final class BundleToken {
  static let bundle: Bundle = {
    #if SWIFT_PACKAGE
    return Bundle.module
    #else
    return Bundle(for: BundleToken.self)
    #endif
  }()
}
// swiftlint:enable convenience_type
bundle = BundleToken.bundle

//: #### Example of code generated by `xcassets` parser with "swift5" template

#if os(macOS)
  import AppKit
#elseif os(iOS)
  import ARKit
  import UIKit
#elseif os(tvOS) || os(watchOS)
  import UIKit
#endif
import PlaygroundSupport

// swiftlint:disable superfluous_disable_command
// swiftlint:disable file_length

// MARK: - Asset Catalogs

// swiftlint:disable identifier_name line_length nesting type_body_length type_name
internal enum Asset {
  internal enum Files {
    internal static let data = DataAsset(name: "Data")
    internal enum Json {
      internal static let data = DataAsset(name: "Json/Data")
    }
    internal static let readme = DataAsset(name: "README")
  }
  internal enum Food {
    internal enum Exotic {
      internal static let banana = ImageAsset(name: "Exotic/Banana")
      internal static let mango = ImageAsset(name: "Exotic/Mango")
    }
    internal enum Round {
      internal static let apricot = ImageAsset(name: "Round/Apricot")
      internal static let apple = ImageAsset(name: "Round/Apple")
      internal enum Double {
        internal static let cherry = ImageAsset(name: "Round/Double/Cherry")
      }
      internal static let tomato = ImageAsset(name: "Round/Tomato")
    }
    internal static let `private` = ImageAsset(name: "private")
  }
  internal enum Styles {
    internal enum _24Vision {
      internal static let background = ColorAsset(name: "24Vision/Background")
      internal static let primary = ColorAsset(name: "24Vision/Primary")
    }
    internal static let orange = ImageAsset(name: "Orange")
    internal enum Vengo {
      internal static let primary = ColorAsset(name: "Vengo/Primary")
      internal static let tint = ColorAsset(name: "Vengo/Tint")
    }
  }
  internal enum Symbols {
    internal static let exclamationMark = SymbolAsset(name: "Exclamation Mark")
    internal static let plus = SymbolAsset(name: "Plus")
  }
  internal enum Targets {
    internal static let bottles = ARResourceGroupAsset(name: "Bottles")
    internal static let paintings = ARResourceGroupAsset(name: "Paintings")
    internal static let posters = ARResourceGroupAsset(name: "Posters")
  }
}
// swiftlint:enable identifier_name line_length nesting type_body_length type_name

//: #### Usage Example

// images

// Tip: Use "Show Result" box on the right to display the images inline in playground
let image1 = UIImage(asset: Asset.Food.Exotic.banana)
let image2 = Asset.Food.Round.tomato.image

// Show fruits animated in the playground's liveView
PlaygroundPage.current.liveView = {
  let assets = [
    Asset.Food.Exotic.banana,
    Asset.Food.Exotic.mango,
    Asset.Food.Round.apricot,
    Asset.Food.Round.apple,
    Asset.Food.Round.tomato,
    Asset.Food.Round.Double.cherry
  ]
  let iv = UIImageView(frame: CGRect(x: 0, y: 0, width: 200, height: 200))
  iv.animationImages = assets.map(\.image)
  iv.animationDuration = TimeInterval(assets.count)/2 // 0.5s per image
  iv.startAnimating()
  return iv
}()

// colors
let color1 = UIColor(asset: Asset.Styles.Vengo.primary)
let color2 = Asset.Styles.Vengo.tint.color


/* Colors support variations for different interface styles (light/dark mode) */ _ = {
  let vc = UIViewController()
  vc.overrideUserInterfaceStyle = .dark
  vc.view.backgroundColor = Asset.Styles.Vengo.primary.color
  vc.view // Use "Show Result" box on the right to display contextualized color inline in playground

  vc.overrideUserInterfaceStyle = .light
  vc.view // Use "Show Result" box on the right to display contextualized color inline in playground
}()

// data
let dataAsset1 = NSDataAsset(asset: Asset.Files.data)
let dataAsset2 = Asset.Files.readme.data
let readmeText = String(data: dataAsset2.data, encoding: .utf8) ?? "-"
print(readmeText)

// AR resources
let paintingReferenceImages = Asset.Targets.paintings.referenceImages
let bottleReferenceObjects = Asset.Targets.bottles.referenceObjects

// symbols
let plus = Asset.Symbols.plus.image
let style = UIImage.SymbolConfiguration(textStyle: .headline)
let styled = Asset.Symbols.exclamationMark.image(with: style)

// SwiftUI

import SwiftUI
import PlaygroundSupport

struct ContentView: View {
  var body: some View {
    VStack {
      Image(decorative: Asset.Food.Exotic.mango)
      Button(action: {}) {
        HStack {
          Asset.Symbols.plus.swiftUIImage
          Text("Add")
        }
      }
      .padding()
      .foregroundColor(Asset.Styles.Vengo.tint.swiftUIColor)
      .background(Asset.Styles.Vengo.primary.swiftUIColor)
      .cornerRadius(.infinity)
    }
  }
}

PlaygroundPage.current.setLiveView(ContentView())

